package com.scs.application.modules.fsd.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.fsd.entity.FsdGroup;
import com.scs.application.modules.fsd.service.GroupService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description: 用户群组
 */
@RestController
@RequestMapping("/back_front/groups")
public class GroupController extends CrudController<GroupService, FsdGroup> {

    @PostMapping(value = "/createService")
    public RestResult saveGroup(@RequestBody Map<String,String> map){
        Boolean ok=service.saveGroup(map.get("groupName"),map.get("remark"));
        if(ok) return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }
    @PostMapping(value = "/editService")
    public RestResult editGroup(@RequestBody Map<String,String> map){
        Boolean ok=service.editGroupById(map.get("groupName"),map.get("remark"),map.get("id"));
        if(ok) return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }

    /**
     * 获取数据列表
     */
    @GetMapping(value ="/getService" )
    public RestResult getGroupList(@RequestParam("keyword") String keyword, @RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize") Integer pageSize){
        Map<String, Object> groups= service.getGroups(keyword,currentPage,pageSize);
        return RestResult.ok("get Groups list success",groups);
    }

    @GetMapping(value ="/getAllService" )
    public RestResult getAllGroup(){
        return findAll(true);
    }
}
